package com.wwwarehouse.taskcenter.fragment.job_point.step2.child;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.taskcenter.R;

import static com.wwwarehouse.taskcenter.fragment.job_point.AddJobPointCardFragment.KEY_WAREHOUSE_UKID;

/**
 * Created by Jackie on 2017/10/27
 * 子作业点位置维度  选择添加方式
 */

public class ChooseAddWayChildPositionFragment extends BaseFragment implements View.OnClickListener {
    private View mRootView;

    private RelativeLayout mWayAreaLayout;
    private RelativeLayout mWayPointLayout;

    private String mWarehouseUkid;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_choose_add_way_child_position, container, false);
        return mRootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initView();
        initData();
        initEvent();
    }

    private void initView() {
        mWayAreaLayout = findView(mRootView, R.id.rl_way_area);
        mWayPointLayout = findView(mRootView, R.id.rl_way_point);
    }

    private void initData() {
        Bundle bundle = getArguments();

        if (bundle != null) {
            mWarehouseUkid = bundle.getString(KEY_WAREHOUSE_UKID);
        }
    }

    private void initEvent() {
        mWayAreaLayout.setOnClickListener(this);
        mWayPointLayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();

        if (id == R.id.rl_way_area) {
            Bundle bundle = new Bundle();
            bundle.putString(KEY_WAREHOUSE_UKID, mWarehouseUkid);

            ChooseAddWayChildPositionByAreaFragment chooseAddWayChildPositionByAreaFragment = new ChooseAddWayChildPositionByAreaFragment();
            chooseAddWayChildPositionByAreaFragment.setArguments(bundle);
            pushFragment(chooseAddWayChildPositionByAreaFragment);
        } else if (id == R.id.rl_way_point) {
            Bundle bundle = new Bundle();
            bundle.putString(KEY_WAREHOUSE_UKID, mWarehouseUkid);

            ChooseAddWayChildPositionByPointFragment chooseAddWayChildPositionByPointFragment = new ChooseAddWayChildPositionByPointFragment();
            chooseAddWayChildPositionByPointFragment.setArguments(bundle);
            pushFragment(chooseAddWayChildPositionByPointFragment);
        }
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof ChooseAddWayChildPositionFragment) {
            mActivity.setTitle(R.string.choose_add_type);
        }
    }

    @Override
    public void requestDatas() {

    }
}
